package com.appkubes.mall.admin.application.goods.sku.service.impl;

import com.appkubes.common.utils.data.string.UUIDUtils;
import com.appkubes.mall.admin.application.goods.sku.dao.SpecificAttributeDao;
import com.appkubes.mall.admin.application.goods.sku.entity.model.AttributeModel;
import com.appkubes.mall.admin.application.goods.sku.service.SpecificAttributeService;
import com.appkubes.mall.core.po.MallSpecificAttribute;
import com.appkubes.mall.core.po.MallSpecificAttributeExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecificAttributeServiceImpl implements SpecificAttributeService {
    @Autowired
    SpecificAttributeDao specificAttributeDao;

    @Override
    public int add(MallSpecificAttribute specificAttribute) {
        specificAttribute.setSpecificAttributeKey(UUIDUtils.getUUID());
        specificAttribute.setAppKey(null);
        specificAttribute.setAppKey(null);
        return specificAttributeDao.insertSelective(specificAttribute);
    }

    @Override
    public int del(String key) {
        return specificAttributeDao.deleteByPrimaryKey(key);
    }

    @Override
    public int delByParentKey(String key) {
        MallSpecificAttributeExample example = new MallSpecificAttributeExample();
        MallSpecificAttributeExample.Criteria criteria = example.createCriteria();
        criteria.andSpecificTypeKeyEqualTo(key);
        return specificAttributeDao.deleteByExample(example);
    }

    @Override
    public List<AttributeModel> getList(String appKey, String specificTypeKey) {
        List<AttributeModel> models = specificAttributeDao.getList(appKey, specificTypeKey);
        return models;
    }
}
